///////////////////////////////////////////////////////////////////////////////////////
//  This program is for testing ClassMC, for details pls see CosmologyTest.cpp
//
//  @ Sep-11-2017
//  Youhua Xu
///////////////////////////////////////////////////////////////////////////////////////

#include "ClassMC.hpp"

using namespace std;
using namespace imcmc;
using namespace imcmc::parser;

CosmoTheory theory;
DataList    datalist;

int main( int argc, char* argv[] ){

    MPI::Init(argc, argv);

    int rank = MPI::COMM_WORLD.Get_rank();

    if( argc < 2 ){
        if( rank == 0 ){
            cout << "\n"
                 << argv[0]
                 << ": no input parameter file found, exit now! \n";
        }

        MPI::Finalize();
		return 0;
    }

//  get configuration file
    string paramfile(argv[1]);

//  configure datasets.
	datalist.Init(paramfile);

//  configure cosmological model
    theory.Init(paramfile);


//  decide what to calculate and pass cosmological MCMC parameters to datalist.ParList
    theory.Init(datalist);

    double H0   = theory.engine->get_H0();
    double Om0  = theory.engine->get_Omega_m();

    double lA, R, z_rec;
    double ra_rec, rs_rec;

    z_rec  = theory.engine->z_rec_Hu();

    // pth->ra_rec=pth->da_rec*(1.+pth->z_rec)/pba->a_today;
    ra_rec = theory.engine->get_Da(z_rec)*(1.+z_rec)/theory.engine->get_a_today();

    rs_rec = theory.engine->get_rs(z_rec);
    lA     = _PI_*ra_rec/rs_rec;
    R      = sqrt(Om0)*H0*ra_rec/(_c_*1e-3);

    std::setprecision(12);
    std::setw(15);

    cout << "\nCMB diatance parameters are (Hu-fitting):\n";
    cout << "ra_rec = " << ra_rec << endl;
    cout << "rs_rec = " << rs_rec << endl;
    cout << "lA     = " << lA << endl;
    cout << "R      = " << R << endl;
    cout << "z_rec  = " << z_rec << endl;


    ra_rec = theory.engine->ra_rec();
    rs_rec = theory.engine->rs_rec();
    z_rec  = theory.engine->z_rec();

    lA     = _PI_*ra_rec/rs_rec;
    R      = sqrt(Om0)*H0*ra_rec/(_c_*1e-3);
    cout << "\nCMB diatance parameters are:\n";
    cout << "ra_rec = " << ra_rec << endl;
    cout << "rs_rec = " << rs_rec << endl;
    cout << "lA     = " << lA << endl;
    cout << "R      = " << R << endl;
    cout << "z_rec  = " << z_rec << endl;


    MPI::Finalize();
}
